package com.flower.service.impl;

import com.flower.mapper.OutMapper;
import com.flower.model.entity.Out;
import com.flower.model.entity.Outstorage;
import com.flower.service.IOutService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lm
 * @create 2022-03-26 15:23
 */
@Service
public class OutServiceImpl implements IOutService {

    @Autowired
    private OutMapper outMapper;

    @Override
    public Page<Outstorage> findPage(Page<Outstorage> page, String outId, String outOper, String outCustomer,
                                     String startTime, String endTime) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return outMapper.findPage(page, outId, outOper, outCustomer, startTime, endTime);

    }

    @Override
    public Page<Outstorage> findPage1(Page<Outstorage> page, String startTime, String endTime) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return outMapper.findPage1(page, startTime, endTime);
    }

    @Override
    public Double sumByToday() {
        return outMapper.sumByToday();
    }

    @Override
    public Double sumByPaid() {
        return outMapper.sumByPaid();
    }

    @Override
    public int saleValidate() {
        Integer Validate;

        Validate = outMapper.totalsale();

        if (Validate == null)
            return 0;
        return Validate.intValue();
    }

    @Override
    public void saveOrUpdate(Outstorage outstorage) {
        if (outstorage.getId() == null)
            outMapper.add(outstorage);
        else
            outMapper.update(outstorage);
    }

    @Override
    public List<Out> list() {
        return outMapper.list();
    }

    @Override
    public void removeById(Integer id) {
        outMapper.removeById(id);
    }

    @Override
    public void removeByIds(List<Integer> ids) {
        ids.forEach(id -> outMapper.removeById(id));
    }
}
